﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Abs.App
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        private string adminMaster = "~/MasterPages/AdminMaster.Master";
        private string userMaster = "~/MasterPages/UserMaster.Master";

        protected void Page_PreInit(object sender, EventArgs e)
        {

            //Determine which master page to use based on the role of the account (normal user/ admin)
            if (Session["Role"] != null && ((int)Session["Role"] == (int)Abs.Core.Models.User.RoleEnum.Admin))
            {
                MasterPageFile = adminMaster;
            }
            else
            {
                MasterPageFile = userMaster;
            }


        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //redirect logged in normal users so that they cant register another account
            if (Session["Role"] != null && ((int)Session["Role"] == (int)Abs.Core.Models.User.RoleEnum.User))
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        
        protected void Button_Submit_Click(object sender, EventArgs e)
        {
            var userManagement = Abs.Core.Management.Manage.User;
            if(userManagement.Create(Text_Email.Text, Text_Password.Text, Text_Name.Text))
            {
                Session["RegName"] = Text_Name.Text;
                Session["RegPass"] = Text_Password.Text;
                Session["RegEmail"] = Text_Email.Text;
                Response.Redirect("~/User/Registration_Success.aspx");
            }
            
        }
    }
}